﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ApplyPathTemplateAction.CApApplyPathTemplateUtil
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Olp;


namespace DnProcessSimulateCommands.ApplyPathTemplateAction;

internal class CApApplyPathTemplateUtil
{
  internal TxRobot GetRobot(ITxOperation operation)
  {
    TxRobot robot = (TxRobot) null;
    if (operation is TxCompoundOperation)
    {
      TxTypeFilter txTypeFilter = new TxTypeFilter();
      txTypeFilter.AddIncludedType(typeof (ITxWeldOperation));
      txTypeFilter.AddIncludedType(typeof (TxGenericRoboticOperation));
      txTypeFilter.AddIncludedType(typeof (ITxContinuousOperation));
      TxObjectList allDescendants = (operation as TxCompoundOperation).GetAllDescendants((ITxTypeFilter) txTypeFilter);
      if (((Collection<ITxObject>) allDescendants).Count > 0)
      {
        robot = this.GetRobot(((Collection<ITxObject>) allDescendants)[0] as ITxOperation);
        for (int index = 1; index < ((Collection<ITxObject>) allDescendants).Count; ++index)
        {
          if (TxRobot.op_Inequality(robot, (ITxObject) this.GetRobot(((Collection<ITxObject>) allDescendants)[index] as ITxOperation)))
          {
            robot = (TxRobot) null;
            break;
          }
        }
      }
    }
    else
      robot = new TxOlpControllerUtilities().GetRobot(operation);
    return robot;
  }

  internal TxObjectList GetAllSubRoboticOperations(TxObjectList operations)
  {
    TxObjectList roboticOperations = new TxObjectList();
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    txTypeFilter.AddIncludedType(typeof (ITxWeldOperation));
    txTypeFilter.AddIncludedType(typeof (TxGenericRoboticOperation));
    txTypeFilter.AddIncludedType(typeof (TxRoboticSeamOperation));
    txTypeFilter.AddIncludedType(typeof (ITxContinuousOperation));
    foreach (ITxObject operation in (Collection<ITxObject>) operations)
    {
      if (operation is TxCompoundOperation)
      {
        foreach (ITxObject allDescendant in (Collection<ITxObject>) (operation as TxCompoundOperation).GetAllDescendants((ITxTypeFilter) txTypeFilter))
        {
          if (!((Collection<ITxObject>) roboticOperations).Contains(allDescendant))
            ((Collection<ITxObject>) roboticOperations).Add(allDescendant);
        }
      }
      else if (!((Collection<ITxObject>) roboticOperations).Contains(operation))
        ((Collection<ITxObject>) roboticOperations).Add(operation);
    }
    return roboticOperations;
  }
}
